<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!--教师基本信息-->
      <el-col :span="4" :xs="5">
        <treeIndex :deptOptions="deptOptions" @handleNode="handleNodeClick" :title="'部门信息'"></treeIndex>
      </el-col>
      <el-col :span="20" :xs="24">
        <searchForm
          :formOptions="formOptions"
          @onSearch="onSearch"
          @onReset="onReset"
          :formLabelWidth="formLabelWidth"
          v-show="showSearch"
        />
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              v-hasPermi="['basic:teacher:add']"
            >新增</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="success"
              plain
              icon="el-icon-edit"
              size="mini"
              :disabled="single"
              @click="handleUpdate"
              v-hasPermi="['basic:teacher:edit']"
            >修改</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="el-icon-delete"
              size="mini"
              :disabled="multiple"
              @click="handleDelete"
              v-hasPermi="['basic:teacher:remove']"
            >删除</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="info"
              plain
              icon="el-icon-upload2"
              size="mini"
              @click="upload.open = true"
              v-hasPermi="['basic:teacher:import']"
            >导入</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="warning"
              plain
              icon="el-icon-download"
              size="mini"
              @click="handleExport"
              v-hasPermi="['basic:teacher:export']"
            >导出</el-button>
          </el-col>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>
        <!-- 用户导入对话框 -->
        <el-dialog title="excel导入" :visible.sync="upload.open" width="400px" append-to-body>
          <el-upload
            ref="upload"
            :limit="1"
            accept=".xlsx, .xls"
            :headers="upload.headers"
            :action="upload.url + '?updateSupport=' + upload.updateSupport"
            :disabled="upload.isUploading"
            :on-progress="handleFileUploadProgress"
            :on-success="onSuccess"
            :auto-upload="false"
            drag
          >
            <i class="el-icon-upload"></i>
            <div class="el-upload__text">
              将文件拖到此处，或
              <em>点击上传</em>
            </div>
            <div class="el-upload__tip text-center" slot="tip">
              <div class="el-upload__tip" slot="tip">
                <el-checkbox v-model="upload.updateSupport" />是否更新已经存在的用户数据
              </div>
              <span>仅允许导入xls、xlsx格式文件。</span>
              <el-link
                type="primary"
                :underline="false"
                style="font-size: 12px; vertical-align: baseline"
                @click="importTemplate"
              >下载模板</el-link>
            </div>
          </el-upload>
          <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitUpload">确 定</el-button>
            <el-button @click="upload.open = false">取 消</el-button>
          </div>
        </el-dialog>
        <el-dialog title="导入成功或失败提示信息" :visible.sync="uploadData" width="500px" append-to-body>
          <el-descriptions :column="1">
            <el-descriptions-item label="上传总数据">{{studenData.totalSize}}条</el-descriptions-item>
            <el-descriptions-item label="成功数据">{{studenData.successSize}}条</el-descriptions-item>
            <el-descriptions-item label="失败数据">{{studenData.errorSize}}条</el-descriptions-item>
            <el-descriptions-item label="失败原因">
              <!-- <span v-html="studenData.failureMsg"></span> -->
              {{ studenData.errorMsg }}
            </el-descriptions-item>
          </el-descriptions>
          <span slot="footer" class="dialog-footer">
            <el-button @click="uploadData = false">取 消</el-button>
            <el-button type="primary" @click="uploadData = false">确 定</el-button>
          </span>
        </el-dialog>
        <el-table :data="roleList" @selection-change="handleSelectionChange" v-loading="loading">
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="工号" prop="tno" :show-overflow-tooltip="true" align="center" />
          <el-table-column label="姓名" prop="name" align="center" />
          <!-- <el-table-column label="单位号" prop="roleSort" align="center" /> -->
          <el-table-column
            label="单位名称"
            :show-overflow-tooltip="true"
            prop="deptNames"
            align="center"
          />
          <el-table-column label="性别" prop="sex" align="center">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.sex" />
            </template>
          </el-table-column>
          <el-table-column
            label="出生年月"
            prop="birthday"
            align="center"
            :show-overflow-tooltip="true"
          />
          <el-table-column label="民族" prop="nation" align="center">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.bc_nation_type" :value="scope.row.nation"></dict-tag>
            </template>
          </el-table-column>
          <el-table-column
            label="身份证号"
            :show-overflow-tooltip="true"
            prop="cardCode"
            align="center"
          />
          <el-table-column
            label="政治面貌"
            prop="political"
            align="center"
            :show-overflow-tooltip="true"
          >
            <template slot-scope="scope">
              <dict-tag :options="dict.type.bc_political_type" :value="scope.row.political" />
            </template>
          </el-table-column>
          <el-table-column
            label="岗位状态"
            prop="postStatus"
            align="center"
            :show-overflow-tooltip="true"
          >
            <template slot-scope="scope">
              <dict-tag :options="dict.type.basic_post_status" :value="scope.row.postStatus" />
            </template>
          </el-table-column>
          <el-table-column label="曾用名" prop="formerName" align="center" />
          <el-table-column label="籍贯" prop="birthplaceName" align="center">
         
          </el-table-column>
          <el-table-column label="学历" prop="education" align="center">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.basic_education_type" :value="scope.row.education" />
            </template>
          </el-table-column>
          <el-table-column label="学位" prop="acDegree" align="center">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.basic_degree_type" :value="scope.row.acDegree" />
            </template>
          </el-table-column>
          <el-table-column label="编制类型" prop="braidType" align="center">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.basic_braid_type" :value="scope.row.braidType" />
            </template>
          </el-table-column>
          <el-table-column label="血型" prop="bloodType" align="center">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.basic_blood_type" :value="scope.row.bloodType" />
            </template>
          </el-table-column>
          <el-table-column label="职称" prop="title" align="center">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.basic_title_type" :value="scope.row.title" />
            </template>
          </el-table-column>
          <el-table-column label="职称级别" prop="titleLevel" align="center">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.basic_title_level" :value="scope.row.titleLevel" />
            </template>
          </el-table-column>
          <el-table-column label="教师性质" prop="nature" align="center">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.basic_teacher_nature" :value="scope.row.nature" />
            </template>
          </el-table-column>
          <el-table-column label="操作" fixed="right" align="center" width="150">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['basic:teacher:edit']"
              >修改</el-button>
              <el-button
                size="mini"
                type="text"
                @click="handleDelete(scope.row)"
                v-hasPermi="['basic:teacher:remove']"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
         <!-- 用户导出弹窗 -->
     <el-dialog title="导出" class="exportDlg" :visible.sync="exportVisible" width="520px">
      <el-form ref="exportRef" :model="exportParams" :rules="exportRules" label-width="120px">
        <el-form-item label="页码" prop="pageNum">
          <el-input-number v-model="exportParams.pageNum" controls-position="right" :min="1"></el-input-number>
        </el-form-item>
      </el-form>
      <p style="padding-left: 82px;">注：根据页码导出对应数据条数，每页最多导出5000条；<br/>
        例：页面输入2则导出5001~10000之间的数据；
      </p>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="downloadStudentInfo">确 定</el-button>
        <el-button @click="exportVisible = false">取 消</el-button>
      </div>
    </el-dialog>
        <!-- 添加或修改教师基本信息 -->
        <el-dialog
          :title="title"
          :visible.sync="open"
          width="60%"
          append-to-body
          @close="CloseIn"
          destroy-on-close
        >
          <el-form ref="form" :model="form" :rules="rules" label-width="95px">
            <el-row>
              <el-col :span="8">
                <el-form-item label="所属院系" prop="deptId">
                  <el-cascader
                    v-model="form.deptId"
                    :options="deptOptions"
                    :props="{ value: 'id',currentLabels: 'label',checkStrictly: true }"
                    style="width: 100%"
                    @change="handleChange"
                    clearable
                  ></el-cascader>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="来校日期" prop="admissionTime">
                  <el-date-picker
                    v-model="form.admissionTime"
                    type="date"
                    value-format="yyyy-MM-dd"
                    placeholder="选择来校日期"
                    style="width: 100%"
                  ></el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="工号" prop="tno">
                  <el-input v-model.trim="form.tno" clearable placeholder="请输入工号" maxlength="30" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="姓名" prop="name">
                  <el-input v-model.trim="form.name" clearable placeholder="请输入姓名" maxlength="10" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="性别" prop="sex">
                  <el-select v-model="form.sex" clearable placeholder="请选择性别" style="width: 100%">
                    <el-option
                      v-for="dict in dict.type.sys_user_sex"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="在职状态" prop="postStatus">
                  <el-select v-model="form.postStatus" clearable placeholder="请选择在职状态" style="width: 100%">
                    <el-option
                      v-for="dict in dict.type.basic_post_status"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="血型" prop="bloodType">
                  <el-select
                    clearable
                    v-model="form.bloodType"
                    placeholder="请选择血型"
                    style="width: 100%"
                  >
                    <el-option
                      v-for="dict in dict.type.basic_blood_type"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="身份证件号" prop="cardCode">
                  <el-input
                    v-model.trim="form.cardCode"
                    placeholder="请输入身份证件号"
                    clearable
                    maxlength="18"
                    @blur="codeBulr"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="出生日期" prop="birthday">
                  <el-date-picker
                    v-model="form.birthday"
                    disabled
                    type="date"
                    placeholder="选择出生日期"
                    style="width: 100%"
                    value-format="yyyy-MM-dd"
                    format="yyyy-MM-dd"
                  ></el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="联系方式" prop="phone">
                  <el-input v-model.trim="form.phone" placeholder="请输入联系方式" maxlength="11"/>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="民族" prop="nation">
                  <el-select v-model="form.nation" placeholder="请选择民族" style="width: 100%">
                    <el-option
                      v-for="dict in dict.type.bc_nation_type"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="政治面貌" prop="political">
                  <el-select v-model="form.political" placeholder="请选择政治面貌" style="width: 100%">
                    <el-option
                      v-for="dict in dict.type.bc_political_type"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="曾用名" prop="formerName">
                  <el-input v-model.trim="form.formerName" placeholder="请输入曾用名" maxlength="10" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="籍贯" prop="bnpId">
                  <el-cascader v-model="form.bnpId" 
                :props="{ value: 'unitCode',currentLabels: 'label' }"
                 :options="options" @change="handlePlace"></el-cascader>
                  <!-- <el-input v-model.trim="form.bnpId" placeholder="请输入籍贯" maxlength="30" /> -->
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="学历" prop="education">
                  <el-select v-model="form.education" placeholder="请选择学历" style="width: 100%">
                    <el-option
                      v-for="dict in dict.type.basic_education_type"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="学位" prop="acDegree">
                  <el-select v-model="form.acDegree" placeholder="请选择学位" style="width: 100%">
                    <el-option
                      v-for="dict in dict.type.basic_degree_type"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="编制类型" prop="braidType">
                  <el-select v-model="form.braidType" placeholder="请选择编制类型" style="width: 100%">
                    <el-option
                      v-for="dict in dict.type.basic_braid_type"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="职称" prop="title">
                  <el-select v-model="form.title" placeholder="请选择职称" style="width: 100%">
                    <el-option
                      v-for="dict in dict.type.basic_title_type"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="职称级别" prop="titleLevel">
                  <el-select v-model="form.titleLevel" placeholder="请选择职称级别" style="width: 100%">
                    <el-option
                      v-for="dict in dict.type.basic_title_level"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="任职类型" prop="officeType">
                  <el-select v-model="form.officeType" placeholder="请选择任职类型" style="width: 100%">
                    <el-option
                      v-for="dict in dict.type.bc_office_type"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="教师性质" prop="nature">
                  <el-select v-model="form.nature" placeholder="请选择教师性质" style="width: 100%">
                    <el-option
                      v-for="dict in dict.type.basic_teacher_nature"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
          </div>
        </el-dialog>
      </el-col>
    </el-row>
    
  </div>
  
</template>
<script>
import { deptTreeSelect } from "@/api/system/user";
import { getDicts } from "@/api/system/dict/type";
import {
  teacherList,
  teacherInfor,
  updateTeacher,
  addTeacher,
  delTeacher
} from "@/api/information/teacherInfor";
import searchForm from "@/components/Search/searchForm.vue";
import treeIndex from "@/components/tree/index.vue";
import { getToken } from "@/utils/auth";
import Validators from "@/utils/validate.js";
import { getProvinceTree } from "@/api/information/classInfor";
export default {
  components: { searchForm, treeIndex },
  dicts: [
    "bc_political_type", // 政治面貌
    "bc_nation_type", // 民族类型
    "basic_braid_type", // 编制类型
    "bc_node_type", // 入学前户口类别
    "follow_status", // 是否关注对象
    "basic_education_type", // 学历类型
    "basic_degree_type", // 学位类型
    "basic_title_type", // 职称类型
    "basic_title_level", // 职称级别
    "basic_teacher_nature", // 教师性质
    "sys_user_sex", // 性别
    "basic_blood_type", // 血型
    "bc_health_status", // 健康状态
    "basic_post_status", // 在职状态
    "bc_office_type", // 任职类型
  ],
  data() {
    return {
      options: [],
      deptOptions: [],
      // 遮罩层
      loading: true,
      formLabelWidth: "80px",
      formOptions: [
        // {
        //   label: "单位名称",
        //   prop: "deptNames",
        //   element: "el-input",
        //   placeholder: "请输入名称"
        // },
        {
          label: "姓名",
          prop: "name",
          element: "el-input",
          placeholder: "请输入姓名"
        },
        {
          label: "工号",
          prop: "tno",
          element: "el-input",
          placeholder: "请输入工号"
        },
        {
          label: "岗位状态",
          prop: "postStatus",
          element: "el-select",
          options: [],
          initValue: '11',
          placeholder: "请选择岗位状态"
        },
      ],
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 角色表格数据
      roleList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示弹出层（数据权限）
      menuExpand: false,
      menuNodeAll: false,
      deptExpand: true,
      deptNodeAll: false,
      // 日期范围
      dateRange: [],
      // 菜单列表
      menuOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        deptId: "",
        postStatus: '11'

      },
      // 表单参数
      form: {},
      defaultProps: {
        children: "children",
        label: "label"
      },
      exportParams:{
        pageNum: 1,
        pageSize: 5000
      },
      exportVisible: false,
      exportRules:{
        pageNum: [
          {
            required: true,
            message: '请输入页码',
            trigger: "blur"
          }
        ],
      },
      uploadData: false, // 提示信息弹框
      studenData: {}, //提示返回值
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/basic/teacher/importTeacher"
      },
      name: [],
      // 表单校验
      rules: {
        deptId: [
          { required: true, message: "请选择所属院系", trigger: "change" }
        ],
        admissionTime: [
          { required: true, message: "请选择来校时间", trigger: "change" }
        ],
        postStatus: [
          { required: true, message: "请选择岗位状态", trigger: "change" }
        ],
        tno: [
          {
            required: true,
            text: "请输入工号",
            validator: Validators.istext,
            trigger: "blur"
          }
        ],
        name: [
          {
            required: true,
            text: "请输入姓名",
            validator: Validators.isString,
            trigger: "blur"
          }
        ],
        sex: [{ required: true, message: "请选择性别", trigger: "change" }],
        bloodType: [
          { required: false, message: "请选择血型", trigger: "change" }
        ],
        cardCode: [
          { required: false, message: "请输入身份证号", trigger: "blur" },
          {
            message: "请输入正确的身份证号",
            pattern: /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]+$/,
            trigger: "blur"
          }
        ],
        phone: [
          { required: false, message: "请输入联系方式", trigger: "blur" },
          {
            message: "请输入正确的身份证号",
            pattern:  /^1\d{10}$/,
            trigger: "blur"
          }
        ],
        birthday: [
          { required: false, message: "请选择出生日期", trigger: "change" }
        ],
        nation: [{ required: false, message: "请选择民族", trigger: "change" }],
        political: [
          { required: false, message: "请选择政治面貌", trigger: "change" }
        ],
        formerName: [
          {
            required: false,
            text: "请输入曾用名",
            // validator: Validators.isString,
            trigger: "blur"
          }
        ],
        bnpId: [
          { required: false, message: "请选择籍贯", trigger: "change" },
        ],
        education: [
          { required: false, message: "请选择学历", trigger: "change" }
        ],
        acDegree: [
          { required: false, message: "请选择学位", trigger: "change" }
        ],
        braidType: [
          { required: false, message: "请选择编制类型", trigger: "change" }
        ],
        title: [{ required: false, message: "请选择职称", trigger: "change" }],
        titleLevel: [
          { required: false, message: "请选择职称级别", trigger: "change" }
        ],
        nature: [
          { required: false, message: "请选择教师性质", trigger: "change" }
        ]
      }
    };
  },
  created() {
    this.department();
    this.getTree()
    getDicts("basic_post_status").then(res => {
      this.formOptions[2].options = res.data.map(item => {
        return {
          value: item["dictValue"],
          label: item["dictLabel"]
        };
      });
    });
  },
  methods: {
    // 获取搜索表单提交的数据
    onSearch(val) {
      // 查询条件和分页数据合并
      this.queryParams = Object.assign(this.queryParams, val);
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.name = selection.map(item => item.name);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    handleChange(value) {
      if (value) {
        this.form.deptId = value[value.length - 1];
      }
      // this.form.deptId = value[2];
      // this.form.multistage = value + "";
    },
    // 清除表单
    CloseIn() {
      this.form = {};
      this.open = false;
    },
    getTree() {
      getProvinceTree().then(response => {
        this.options = response.data;
      });
    },
    handlePlace(data) {
      this.form.bnpId = data[data.length - 1]
    },
    // 根据身份证号获取出生年月日
    getBirthday(idCard) {
      // 提取生日信息
      var birthday = idCard.substr(6, 8);
      // 解析年、月、日
      var year = birthday.substr(0, 4);
      var month = birthday.substr(4, 2);
      var day = birthday.substr(6, 2);

      // 返回生日信息
      return year + "-" + month + "-" + day;
    },
    // 根据身份证号获取出生年月
    codeBulr() {
      if(this.form.cardCode){
        this.$set(this.form, "birthday", this.getBirthday(this.form.cardCode));
      }
    },
    // 重置
    onReset(data) {
      this.queryParams.deptId = ''
      this.queryParams = Object.assign(this.queryParams, data);
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // tree树形选中的值
    handleNodeClick(data) {
      // console.log(data.label, "选中的值");
      this.queryParams.deptId = data.id;
      this.getList();
    },
    // 获取部门信息
    async department() {
      await deptTreeSelect().then(res => {
        this.deptOptions = res.data;
        this.getList();
      });
    },
    /** 查询角色列表 */
    getList() {
      this.loading = true;
      teacherList(this.queryParams).then(response => {
        this.roleList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download(
        "/basic/teacher/importTemplate",
        {},
        `教师信息模板_${new Date().getFullYear()}-${new Date().getMonth() +
          1}-${new Date().getDate()}.xlsx`
      );
    },
    // 点击确定上传文件按钮
    submitUpload() {
      this.$refs.upload.submit();
    },
    //文件上传成功
    onSuccess(response) {
      
      if (response.code == 200) {
        // debugger
        this.$message.success("文件上传成功");
        this.studenData = response.data;
        this.upload.isUploading = false;
        this.$refs.upload.clearFiles();
        this.upload.open = false;
        this.uploadData = true;
      
        this.getList();
      } else {
        this.studenData = response.data;
        this.upload.isUploading = false;
        this.$refs.upload.clearFiles();
        this.upload.open = false;
        this.uploadData = true;
        this.$message.error("文件上传失败");
        // this.getList();
      }
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      
      this.open = true;
      this.title = "新增教师基本信息";
    },
    cancel() {
      this.open = false;
      this.form = {};
    },
    // 修改弹窗
    handleUpdate(row) {
      const roleId = row.id || this.ids;
      teacherInfor(roleId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改教师基本信息";
      });
    },

    /** 选择角色权限范围触发 */
    dataScopeSelectChange(value) {
      if (value !== "2") {
        this.$refs.dept.setCheckedKeys([]);
      }
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updateTeacher(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTeacher(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const roleIds = row.id || this.ids;
      this.name = row.name || this.name;
      this.$modal
        .confirm('是否确认删除姓名"' + this.name + '"的教师数据项？')
        .then(function() {
          return delTeacher(roleIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    downloadStudentInfo() {
      this.$refs.exportRef.validate((valid) => {
        if (valid) {
          this.download(
            "/basic/teacher/export",
            {
              ...this.queryParams,
              ...this.exportParams
            },
            `教师信息_${new Date().getFullYear()}-${new Date().getMonth() +
              1}-${new Date().getDate()}.xlsx`
          );
          this.exportVisible = false
        } else {
          return false;
        }
      });  
    },
    /** 导出按钮操作 */
    handleExport() {
      this.exportVisible = true
    }
  }
};
</script>
<style scoped>
.head-container {
  overflow-x: scroll;
}
</style>